/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 86184
 * Date: 2023-06-19
 * Time: 21:26
 */

class Value{//方法二：类和对象2
    private int val;

    //get/set方法
    public int getVal(){
        return this.val;
    }

    public void setVal(int val) {
        this.val = val;
    }
}

class MyValue{//方法二：类和对象1
    public int value;
}

public class TestDemo {

    public static void main(String[] args) {//方法四 异或实现
        int a = 3;
        int b = 5;
        System.out.println("a = "+a+"\t"+"b = "+b);
        a = a ^ b;
        b = a ^ b;
        a = a ^ b;
        System.out.println("a = "+a+"\t"+"b = "+b);
    }
    public static void swap2(Value value1,Value value2){//方法二：类和对象2
        int temp = value1.getVal();
        value1.setVal(value2.getVal()) ;
        value2.setVal(temp) ;
    }

    public static void main3(String[] args) {//方法二：类和对象2
        Value  value1 = new Value();
        value1.setVal(30);
        Value  value2 = new Value();
        value2.setVal(50);
        System.out.println("a = "+value1.getVal()+"\t"+"b = "+value2.getVal());
        swap2(value1,value2);
        System.out.println("a = "+value1.getVal()+"\t"+"b = "+value2.getVal());
    }
    public static void swap1(MyValue myValue1,MyValue myValue2){//方法二：类和对象1
        int temp = myValue1.value;
        myValue1.value = myValue2.value;
        myValue2.value = temp;
    }

    public static void main2(String[] args) {//方法二：类和对象1
        MyValue myValue1 = new MyValue();
        myValue1.value = 10;
        MyValue myValue2 = new MyValue();
        myValue2.value = 20;
        System.out.println("a = "+ myValue1.value+"\t"+"b = "+ myValue2.value);
        swap1(myValue1,myValue2);
        System.out.println("a = "+ myValue1.value+"\t"+"b = "+ myValue2.value);
    }

    public static void swap(int[] arr){//方法一：数组
        int temp = arr[0];
        arr[0] = arr[1];
        arr[1] = temp;
    }

    public static void main1(String[] args) {//方法一：数组
        int[] arr = {3,5};
        System.out.println("a = "+arr[0]+"\t"+"b = "+arr[1]);
        swap(arr);
        System.out.println("a = "+arr[0]+"\t"+"b = "+arr[1]);
    }
}
